﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Reflection;
#if !SILVERLIGHT
using System.Runtime.Serialization;
using System.Xml.Serialization;
#endif

namespace AbstraX
{
#if !SILVERLIGHT
    [Serializable]
    [DataContract]
#endif
    public class RemotableException
    {
        private Exception innerException;
#if !SILVERLIGHT
        [XmlElement, DataMember]
#endif
        public string ExceptionType { get; set; }
#if !SILVERLIGHT
        [XmlElement, DataMember]
#endif
        public string HelpLink { get; set; }
#if !SILVERLIGHT
        [XmlElement, DataMember]
#endif
        public RemotableException InnerException { get; set; }
#if !SILVERLIGHT
        [XmlElement, DataMember]
#endif
        public string Message { get; set; }
#if !SILVERLIGHT
        [XmlElement, DataMember]
#endif
        public string Source { get; set; }
#if !SILVERLIGHT
        [XmlElement, DataMember]
#endif
        public string StackTrace { get; set; }
#if !SILVERLIGHT
        [XmlElement, DataMember]
#endif
        public string ToStringText { get; set; }

        public RemotableException()
        {
        }

        public RemotableException(Exception exception)
        {
            innerException = exception;

            if (exception.InnerException != null)
            {
                this.InnerException = new RemotableException(exception.InnerException);
            }

            this.ExceptionType = exception.GetType().Name;
            this.Message = exception.Message;
#if !SILVERLIGHT
            this.HelpLink = exception.HelpLink;
            this.Source = exception.Source;
#endif
            this.StackTrace = exception.StackTrace;
            this.ToStringText = exception.ToString();
        }

        private string ToString()
        {
            return this.ToStringText;
        }
    }
}
